#include<bits/stdc++.h>
#define lt id<<1
#define rt id<<1|1
using namespace std;
inline int read()
{
    int x=0;char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x;
}
const int N=1e6+10,M=N<<1,K=30;
int T,n,a[N],b[M],p[M];
int fa[M],num[M];
bool flag,vis[N][K];
char ans[N];
vector<int>cant[N],son[M];
inline int id1(int x) {return x*2-1;}
inline int id2(int x) {return (x+1)>>1;}
int Find(int x) {return x==fa[x]?x:fa[x]=Find(fa[x]);}
void merge(int x,int y)
{
    x=Find(x),y=Find(y);
    if(x==y) return;
    if(num[x]<num[y]) swap(x,y);
    fa[y]=x,num[x]+=num[y];
}
void del(int x,char ch)
{
    for(int p:son[x])
    {
        ans[p]=ch;
        // cerr<<p<<" "<<ch<<endl;
        for(int v:cant[p]) vis[Find(id1(v))][ch-'a']=1;
    }
}
void manacher()
{
    for(int i=0;i<=(n<<1);i++) fa[i]=i,num[i]=1;
	for(int i=0,r=-1,mid=0;i<=(n<<1);i++)
	{
		if(i<=r) p[i]=min(p[(mid<<1)-i],r-i+1);
		else p[i]=1;
        // cerr<<i<<" "<<b[i]<<endl;
        if((i&&i-b[i]+2<1)||(i<(n<<1)&&i+b[i]-2>=(n<<1))) return flag=1,void();
		while(p[i]<b[i]) merge(i-p[i],i+p[i]),++p[i];
        if(p[i]>b[i]) return flag=1,void();
		if(i+p[i]>r) r=i+p[i]-1,mid=i;
	}
    for(int i=0;i<=(n<<1);i++)
        if(i-p[i]>0&&i+p[i]<(n<<1))
            cant[id2(i-p[i])].push_back(id2(i+p[i])),
            cant[id2(i+p[i])].push_back(id2(i-p[i]));
            // cerr<<id2(i-p[i])<<" "<<id2(i+p[i])<<endl;
}
int main()
{
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    T=read();
    while(T--)
    {
        // for(int i=0;i<=(n<<1);i++) cant[i].clear(),son[i].clear();
        // memset(vis,0,sizeof(vis));
        n=read();flag=0;
        for(int i=1;i<=n;i++) a[i]=read()+1,cant[i].clear();
        for(int i=1;i<(n<<1);i++) b[i]=read()+1;
        for(int i=0;i<=(n<<1);i++) son[i].clear();
        b[0]=b[n<<1]=1;
        manacher();
        if(flag) {puts("-1");continue;}
        // cerr<<"He"<<endl;
        for(int i=1;i<=n;i++)
            ans[i]=' ',son[Find(id1(i))].push_back(i);
        ans[n+1]=' ';
        for(int i=n;i;i--)
        {
            if(ans[a[i]]!=' ') continue;
            // cerr<<a[i]<<endl;
            int f=Find(id1(a[i]));
            for(int j=25;~j;j--)
                if(!vis[f][j])
                {
                    if(i<n&&j>ans[a[i+1]]-'a') continue;
                    if(i<n&&ans[a[i+1]+1]==' '&&j==ans[a[i+1]]-'a'&&a[i+1]+1!=a[i]) continue;
                    ans[a[i]]='a'+j;
                    // if(i==n) break;
                    // int l=a[i],r=a[i+1];
                    // while(ans[l]!=' '&&ans[r]!=' '&&ans[l]==ans[r]) ++l,++r;
                    // if(ans[l]==' ') break;
                    // if(ans[r]==' ') continue;
                    // if(ans[l]<ans[r]) break;
                    // else continue;
                    break;
                }
            del(f,ans[a[i]]);
        }
        for(int i=1;i<=n;i++)
            if(ans[i]==' ') {puts("-1");goto L;}
        for(int i=1;i<=n;i++) putchar(ans[i]);
        putchar('\n');
L:      for(int i=0;i<=(n<<1);i++)
            for(int j=0;j<26;j++) vis[i][j]=0;
    }
    return 0;
}